#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import Any

from cta.impl.action.responsibility_chain_begin_action import ResponsibilityChainBeginAction
from cta.impl.action.responsibility_chain_end_action import ResponsibilityChainEndAction
from cta.interface.action.abstract_action import AbstractAction
from cta.interface.action.prepare_data.abstract_prepare_data_action import AbstractPrepareDataAction
from cta.interface.step.abstract_step import AbstractStep
from web.domain.responsibility_chain_dto import ResponsibilityChainDto


class PrepareDataStep(AbstractStep):
    """
    准备数据步骤
    """

    def __init__(self, prepare_data_action: AbstractPrepareDataAction, successor=None):
        super().__init__(successor)

        # 定义动作
        self.responsibility_chain_begin_action = ResponsibilityChainBeginAction()
        self.prepare_data_action = prepare_data_action
        self.responsibility_chain_end_action = ResponsibilityChainEndAction()
        # 定义动作顺序
        self.responsibility_chain_begin_action.set_successor(self.prepare_data_action)
        self.prepare_data_action.set_successor(self.responsibility_chain_end_action)

    def set_successor(self, successor):
        super().set_successor(successor)

    def exec(self, responsibility_chain_dto: ResponsibilityChainDto = None) -> Any:
        self.responsibility_chain_begin_action.exec(responsibility_chain_dto)
        super().next(responsibility_chain_dto)
